package com.wj.service.impl;


import com.wj.domain.entity.ChapterEntity;
import com.wj.domain.vo.ChapterSimpleVO;
import com.wj.domain.vo.ChapterUpAndDownVO;
import com.wj.domain.vo.ChapterVO;
import com.wj.infrastructure.mapper.ChapterMapper;
import com.wj.infrastructure.repository.ChapterRepository;
import com.wj.service.ChapterService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ChapterServiceImpl implements ChapterService {

    @Resource
    private ChapterMapper chapterMapper;

    @Resource
    private ChapterRepository chapterRepository;

    @Override
    public List<ChapterVO> queryListByBookId(Long bookId) {
        List<ChapterVO> list = chapterMapper.queryListByBookId(bookId);
        return list;
    }

    @Override
    public ChapterVO netChapter(Long bookId, int sort) {
        ChapterVO chapterVO = chapterMapper.getChapterInfo(bookId, sort);
        return chapterVO;
    }

    @Override
    public int getFirstSort(Long bookId) {
        return chapterMapper.getFirstSort(bookId);
    }

    @Override
    public int countChapter(Long bookId) {
        int chapterNumber = chapterMapper.countChapter(bookId);
        return chapterNumber;
    }

    @Override
    public ChapterUpAndDownVO getUpAndDown(Long bookId, int sort) {
        ChapterUpAndDownVO chapterUpAndDownVO = new ChapterUpAndDownVO();
        ChapterSimpleVO preChapter = chapterMapper.getPreChapter(bookId, sort);
        ChapterSimpleVO nextChapter = chapterMapper.getNextChapter(bookId, sort);
        chapterUpAndDownVO.setPreChapterVO(preChapter);
        chapterUpAndDownVO.setNextChapterVO(nextChapter);
        return chapterUpAndDownVO;
    }
}